import QtQuick 2.4

import GameSetting 1.0

SettingPageForm {

    GameSetting{
        id:gameSetting
    }

    twoPlayerOptionImage.onClicked: {
        gameSetting.playerNumber  = 2
        showSetting()
    }

    threePlayerOptionImage.onClicked: {
        gameSetting.playerNumber  = 3
        showSetting()
    }

    freezeModeOptionImage.onClicked: {
        gameSetting.gameMode  = 0
        showSetting()
    }

    nonfreezeModeOptionImage.onClicked: {
        gameSetting.gameMode  = 1
        showSetting()
    }

    twentyOptionImage.onClicked: {
        gameSetting.questionNumber  = 20
        showSetting()
    }

    thirtyOptionImage.onClicked: {
        gameSetting.questionNumber  = 30
        showSetting()
    }

    fiftyOptionImage.onClicked: {
        gameSetting.questionNumber  = 50
        showSetting()
    }



    Component.onCompleted: {
        successImageButton.visible  = false
        // 初始化可选项的选中项目
        var setting  = Game.setting()

        gameSetting.playerNumber  = setting.playerNumber
        gameSetting.gameMode  = setting.gameMode
        gameSetting.questionNumber  = setting.questionNumber

        showSetting()
    }

    okImageButton.onClicked: {
        Game.setGameSetting(gameSetting)
        Game.saveSetting()
        successImageButton.visible  = true
    }


    successImageButton.onClicked: {
        stackView.pop();
    }


    function showSetting(){

        if(gameSetting.playerNumber === 2){
            twoPlayerOptionImage.selected  = true
            threePlayerOptionImage.selected  = false
        }
        else{
            twoPlayerOptionImage.selected  = false
            threePlayerOptionImage.selected  = true
        }


        if(gameSetting.gameMode === 0){
            freezeModeOptionImage.selected  = true
            nonfreezeModeOptionImage.selected  = false
        }
        else{
            freezeModeOptionImage.selected  = false
            nonfreezeModeOptionImage.selected  = true
        }

        if(gameSetting.questionNumber === 20){
            twentyOptionImage.selected  = true
            thirtyOptionImage.selected  = false
            fiftyOptionImage.selected  = false
        }
        else if(gameSetting.questionNumber === 30){
            twentyOptionImage.selected  = false
            thirtyOptionImage.selected  = true
            fiftyOptionImage.selected  = false
        }
        else if(gameSetting.questionNumber === 50){
            twentyOptionImage.selected  = false
            thirtyOptionImage.selected  = false
            fiftyOptionImage.selected  = true
        }
    }
}
